#!/usr/bin/python3
#generate the .inp file for packmol
import sys

doc = """tolerance 2.0
filetype pdb
output {output_name}.pdb

structure MDVS.pdb
  number 3610
  inside box 10. 0. 0. 130. 30. 30.
end structure

structure {alcohol}.pdb
  number {n_alcohol}
  inside box 0. 0. 0. 13. 30. 30.
  atoms {special_atom_id}
    inside box 7. 0. 0. 9. 30. 30.
  end atoms
end structure

structure {alcohol}.pdb
  number {n_alcohol}
  inside box 117. 0. 0. 130. 30. 30.
  atoms {special_atom_id}
    inside box 131. 0. 0. 133. 30. 30.
  end atoms
end structure

structure {cation}.pdb
  number {n_cation}
  inside box 10. 0. 0. 130. 30. 30.
end structure

structure {anion}.pdb
  number {n_anion}
  inside box 10. 0. 0. 130. 30. 30.
end structure"""


output_name = "model"
alcohol = "hexan"
n_alcohol = 10
special_atom_id = 2
cation = "Na"
n_cation = 10
anion = "Cl"
n_anion = 10


def make_inp(output_name = output_name,
           alcohol = alcohol,
           n_alcohol = n_alcohol,
           special_atom_id = special_atom_id,
           cation = cation,
           n_cation = n_cation,
           anion = anion,
           n_anion = n_anion):
    
    text = doc.format(output_name = output_name,
           alcohol = alcohol,
           n_alcohol = n_alcohol,
           special_atom_id = special_atom_id,
           cation = cation,
           n_cation = n_cation,
           anion = anion,
           n_anion = n_anion)
    
    #Debug
    print(text)

    return text

#make_inp(output_name="ad",anion = "Mg")

if __name__ == '__main__':
    if len(sys.argv) != 9:
        print("""
        usage:
        ./make_inp.py 10oh17na hexan 10 2 Na 17 Cl 17
        """)
        exit -1
    file_content = make_inp(sys.argv[1],
                         sys.argv[2],
                         sys.argv[3],
                         sys.argv[4],
                         sys.argv[5],
                         sys.argv[6],
                         sys.argv[7],
                         sys.argv[8])
    with open("{0}.inp".format(sys.argv[1]),'w') as f:
        f.write(file_content)
    
#10oh17na hexan 10 2 Na 17 Cl 17

